﻿cmake_minimum_required(VERSION 3.5)

project(DAQ_QT_Demo VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置策略CMP0091为NEW，新策略
if (POLICY CMP0091)
	cmake_policy(SET CMP0091 NEW)
endif (POLICY CMP0091)

# 设备型号 编译时只选择一个添加
set(DEVICE_TYPE "DAQ125")
# set(DEVICE_TYPE "DAQ206")
# set(DEVICE_TYPE "DAQ207")
# set(DEVICE_TYPE "DAQ216")
# set(DEVICE_TYPE "DAQ217")
# set(DEVICE_TYPE "DAQ322")

if(DEVICE_TYPE STREQUAL "DAQ125")
  add_definitions(-DUSE_DAQ125)
elseif(DEVICE_TYPE STREQUAL "DAQ206")
  add_definitions(-DUSE_DAQ206)
elseif(DEVICE_TYPE STREQUAL "DAQ216")
  add_definitions(-DUSE_DAQ216)
elseif(DEVICE_TYPE STREQUAL "DAQ207")
  add_definitions(-DUSE_DAQ207)
elseif(DEVICE_TYPE STREQUAL "DAQ217")
  add_definitions(-DUSE_DAQ217)
elseif(DEVICE_TYPE STREQUAL "DAQ322")
  add_definitions(-DUSE_DAQ322)
else()
  message(FATAL_ERROR "Please define DEVICE_TYPE!")
endif()

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network PrintSupport)

file(GLOB_RECURSE HEADS ${CMAKE_SOURCE_DIR}/src/*.h)
file(GLOB_RECURSE SOURCES ${CMAKE_SOURCE_DIR}/src/*.cpp)
file(GLOB_RECURSE UIS ${PROJECT_SOURCE_DIR}/src/*.ui)
include(${CMAKE_SOURCE_DIR}/../../../DAQ_SDK/DAQ_SDK.cmake)

set(PROJECT_SOURCES ${HEADS} ${SOURCES} ${UIS})

if (MSVC)
  add_compile_options("/utf-8")
endif()

set(DEMO_NAME "DAQ_QT_Demo")
add_executable(${DEMO_NAME} ${PROJECT_SOURCES})
target_link_libraries(${DEMO_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::PrintSupport)
target_link_libraries(${DEMO_NAME} PRIVATE ${DAQ_SDK_DEPENDENT_LIBRARIES})
target_include_directories(${DEMO_NAME} PRIVATE ${DAQ_SDK_INCLUDE_DIRS})
target_include_directories(${DEMO_NAME} PRIVATE ${CMAKE_SOURCE_DIR})

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
	set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.${DEMO_NAME})
endif()
set_target_properties(${DEMO_NAME} PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
		MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS ${DEMO_NAME}
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
	qt_finalize_executable(${DEMO_NAME})
endif()
